package top.fangw.tenant.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.fangw.common.core.entity.BaseIdNameVo;
import top.fangw.common.core.result.Result;
import top.fangw.common.log.annotation.Log;
import top.fangw.tenant.pojo.dto.TenantPackageAddDto;
import top.fangw.tenant.pojo.dto.TenantPackageQueryDto;
import top.fangw.tenant.pojo.entity.TenantPackageInfo;
import top.fangw.tenant.service.ITenantPackageInfoService;

import java.util.List;

/**
 * <p>
 * 用途：提供不同类型的套餐时长、开发功能菜单范围 前端控制器
 * </p>
 *
 * @author fangw
 * @since 2024-01-16
 */
@Tag(name = "租户套餐管理")
@RestController
@RequestMapping("/tenant-package-info")
@RequiredArgsConstructor
public class TenantPackageInfoController {

    private final ITenantPackageInfoService tenantPackageInfoService;

    @Log
    @Operation(summary ="添加租户套餐")
    @PostMapping("/add")
    public Result<?> add(@RequestBody TenantPackageAddDto tenantPackageAddDto) {
        tenantPackageInfoService.add(tenantPackageAddDto);
        return Result.success();
    }

    @Log
    @Operation(summary ="修改租户套餐")
    @PutMapping("/update")
    public Result<?> update(@RequestBody TenantPackageAddDto tenantPackageAddDto) {
        tenantPackageInfoService.updateTenantPackage(tenantPackageAddDto);
        return Result.success();
    }

    @Log
    @Operation(summary ="删除租户套餐")
    @DeleteMapping("/delete")
    public Result<?> delete(@RequestParam String id) {
        tenantPackageInfoService.delete(id);
        return Result.success();
    }

    @Log
    @Operation(summary ="获取套餐详情")
    @GetMapping("/detail")
    public Result<?> get(@RequestParam String id) {
        TenantPackageAddDto res = tenantPackageInfoService.getDetail(id);
        return Result.success(res);
    }

    @Log
    @Operation(summary ="分页查询套餐数据")
    @PostMapping("/pageList")
    public Result<?> pageList(@RequestBody TenantPackageQueryDto queryDto) {
        IPage<TenantPackageInfo> res = tenantPackageInfoService.pageList(queryDto);
        return Result.success(res);
    }

    @Log
    @Operation(summary ="获取套餐下拉列表")
    @GetMapping("/listPackage")
    public Result<?> listPackage() {
        List<BaseIdNameVo> res = tenantPackageInfoService.listPackage();
        return Result.success(res);
    }
}
